package de.tabuma.ssoclient.logik;

import java.util.*;
import de.tabuma.ssoclient.entity.*;
import de.tabuma.lib.webservice.client.*;
/**
 *
 * @author alefen
 */
public class GroupFacade {
    private static String soapUrl = "https://tabumasso.appspot.com/webservice";
    public static int create(Group group, String ssoId) throws Exception {
        String methodName = "GroupService_create";
        String soapAction = "GroupService_create";

        Class returnType = Integer.class;
        Object params[] = {group, ssoId};

        Integer obj = (Integer) ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, returnType, null);
        group.setId(obj.longValue());
        GroupHashFacade.put(group, ssoId);
        return obj.intValue();
    }

    public static void update(Group group, String ssoId) throws Exception {
        String methodName = "GroupService_update";
        String soapAction = "GroupService_update";

        Object params[] = {group, ssoId};
        ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, null, null);
        GroupHashFacade.put(group, ssoId);
    }

    public static Group get(int id, String ssoId) throws Exception {
        String methodName = "GroupService_get";
        String soapAction = "GroupService_get";

        Class returnType = Group.class;
        Object params[] = {Integer.valueOf(id), ssoId};

        Group obj = GroupHashFacade.get(id, ssoId);
        if(obj==null) {
            obj = (Group) ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, returnType, null);
        }
        return obj;
    }

    public static void remove(int id, String ssoId) throws Exception {
        String methodName = "GroupService_remove";
        String soapAction = "GroupService_remove";

        Object params[] = {Integer.valueOf(id), ssoId};

        ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, null, null);
        GroupHashFacade.remove(id, ssoId);
    }

    public static List<Group> getList(String ssoId) throws Exception {
        String methodName = "GroupService_getList";
        String soapAction = "GroupService_getList";

        Class returnType = List.class;
        Class returnType1 = Group.class;
        Object params[] = {ssoId};

        List<Group> obj = GroupHashFacade.getList(ssoId);
        if(obj==null) {
            obj = (List<Group>) ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, returnType, returnType1);
            GroupHashFacade.addList(obj, ssoId);
        }
        return obj;
    }
    
}